home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13871 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  49 lines

  1. Newsgroups: comp.lang.c
  2. Path: netcom.com!smryan
  3. From: smryan@netcom.com (@#$%!?!)
  4. Subject: Re: Beginner need help??????????????
  5. Message-ID: <smryanDpMrH3.Ct5@netcom.com>
  6. Organization: The Programmer formerly known as S M Ryan
  7. X-Newsreader: TIN [version 1.2 PL1]
  8. References: <4kem82$5j3@dewey.csun.edu>
  9. Date: Wed, 10 Apr 1996 05:05:27 GMT
  10. Sender: smryan@netcom12.netcom.com
  11.  
  12. : -------- program 1 -------------------------
  13.  
  14. :   answer = 1 / 3;
  15.  
  16. If both operand of a division are integers, as is in this case, integer
  17. truncation division is used. In this case 1/3 truncated is indeed 0.
  18. C does not have distinguish integer division operator. Nor does it 
  19. consider the eventual destination type. It will _not_ say, oh, this will
  20. be a float, so let's make it one from the beginning.
  21.  
  22. You can override the division operator in C++.
  23.  
  24. : ----------program 2----------------------------
  25. : #include <stdio.h>
  26.  
  27. : float result;
  28.  
  29. :   printf("The result is %d\n", result);
  30.  
  31. C does not make the actual types of a variable list of arguments available
  32. to the caller, and so the caller must guess the types. If the format 
  33. descriptor is %...d, printf assumes it is an int value. On almost any
  34. machine the ints and floats will be encoded differently. You have to use
  35. floating point descriptor such as %f, %g, or %e.
  36.  
  37. : ----------program 3---------------------------
  38.  
  39. : int   integer;
  40. :   printf("The value of integer is %f\n", integer);
  41.  
  42. The same, the other way around.
  43.  
  44. -- 
  45. The Queen, amused, in quiet power,         | smryan@netcom.com  PO Box 1563
  46. will draw the son to darkenned bower.      |          Cupertino, California
  47. Her face is fair, her fragrance rare,      | (xxx)xxx-xxxx            95015
  48. with woven webs for wayward flower.        |         I don't use no smileys
  49.